from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from Answer import Answer

class Unit9:
    def __init__(self, driver):
        self.Chapter9(driver)

    def Chapter9(self, driver):
        answer = Answer()
        # 点击第九单元的学习
        label = driver.find_element(By.CSS_SELECTOR, '#unit60 > div.book_unit_btn_div > button:nth-child(2)')
        driver.execute_script("arguments[0].click();", label)

        # 开始

        # 读取答案并填入
        file_name = 'Unit9Answer.txt'
        with open(file_name) as file_objECt:
            lines = file_objECt.readlines()

        # # c1p2
        # WebDriverWait(driver, 5, 0.5).until(
        #     EC.visibility_of_element_located((By.XPATH, '//*[@id="chapter_menu1"]/li[2]/a')))
        # driver.find_element(By.XPATH, '//*[@id="chapter_menu1"]/li[2]/a').click()
        # answers = [lines[0], lines[1], lines[2], lines[3]]
        # answer.vacancy_question(driver, answers, 1, 4)
        #
        # # c2t1n1
        # WebDriverWait(driver, 5, 0.5).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[2]/a')))
        # driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[2]/a').click()
        # answers = lines[4].split()
        # counts = [1, 1]
        # answer.choice_question(driver, answers, 1, counts, 0)
        #
        # # c2t1n2
        # WebDriverWait(driver, 5, 0.5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="passage"]/li[2]/a')))
        # driver.find_element(By.XPATH, '//*[@id="passage"]/li[2]/a').click()
        # answers = lines[5].split()
        # counts = [2, 2]
        # answer.choice_question(driver, answers, 2, counts, 0)
        #
        # # c2t1n3
        # WebDriverWait(driver, 5, 0.5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="passage"]/li[3]/a')))
        # driver.find_element(By.XPATH, '//*[@id="passage"]/li[3]/a').click()
        # answers = lines[6].split()
        # counts = [3, 3, 1]
        # answer.choice_question(driver, answers, 3, counts, 0)
        #
        # # c2t2c1
        # label = driver.find_element(By.CSS_SELECTOR, '#chapter_menu1 > li:nth-child(2) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answers = lines[7].split()
        # counts = [1, 1, 1, 1, 1]
        # answer.choice_question(driver, answers, 1, counts, 0)
        #
        # # c2t2c2
        # label = driver.find_element(By.CSS_SELECTOR, '#passage > li:nth-child(2) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answer.submit(driver, 2)
        #
        # # c2t3p1
        # label = driver.find_element(By.CSS_SELECTOR, '#chapter_menu1 > li:nth-child(3) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answers = [lines[9], lines[10]]
        # answer.vacancy_question(driver, answers, 1, 2)
        #
        # # c2t3p2
        # WebDriverWait(driver, 5, 0.5).until(
        #     EC.visibility_of_element_located((By.XPATH, '//*[@id="passage"]/li[2]/a')))
        # driver.find_element(By.XPATH, '//*[@id="passage"]/li[2]/a').click()
        # answers = lines[11].split()
        # counts = [1, 1, 1, 1, 1]
        # answer.choice_question(driver, answers, 2, counts, 0)
        #
        # # c2t3p3
        # label = driver.find_element(By.CSS_SELECTOR, '#passage > li:nth-child(3) > a')
        # driver.execute_script("arguments[0].click();", label)
        # driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div[2]/div[2]/div[2]/div[3]/div[2]/p[5]/input').send_keys(lines[12])
        # driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div[2]/div[2]/div[2]/div[3]/div[2]/p[7]/input').send_keys(lines[13])
        # answer.submit(driver, 3)
        #
        # # c2t3p4
        # label = driver.find_element(By.CSS_SELECTOR, '#passage > li:nth-child(4) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answers = lines[14].split()
        # counts = [2, 2, 2, 2, 2]
        # answer.choice_question(driver, answers, 4, counts, 0)
        #
        # # c2t3p5
        # label = driver.find_element(By.CSS_SELECTOR, '#passage > li:nth-child(5) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answer.submit(driver, 5)
        #
        # # c2t3p6
        # label = driver.find_element(By.CSS_SELECTOR, '#passage > li:nth-child(6) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answer.submit(driver, 6)
        #
        # # c5
        # WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[5]/a')))
        # driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[5]/a').click()
        # answers = [lines[17], lines[18], lines[19], lines[20], lines[21], lines[22], lines[23], lines[24], lines[25], lines[26]]
        # answer.vacancy_question(driver, answers, 1, 10)
        #
        # # c6
        # WebDriverWait(driver, 10, 0.5).until(
        #     EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[6]/a')))
        # driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[6]/a').click()
        # answers = [lines[27], lines[28], lines[29], lines[30], lines[31]]
        # answer.vacancy_question(driver, answers, 1, 5)
        #
        # # c7t1
        # WebDriverWait(driver, 10, 0.5).until(
        #     EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[7]/a')))
        # driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/ul/li[7]/a').click()
        # answer.submit(driver, 1)
        #
        # # c7t2
        # label = driver.find_element(By.CSS_SELECTOR, '#chapter_menu1 > li:nth-child(2) > a')
        # driver.execute_script("arguments[0].click();", label)
        # answers = [lines[33], lines[34], lines[35], lines[36], lines[37], lines[38], lines[39], lines[40], lines[41], lines[42], lines[43]]
        # answer.vacancy_question(driver, answers, 1, 11)

        driver.back()